//author:kakake
var Model = /** @class */ (function () {
    function Model() {
    }
    return Model;
}());

//author:kakake
var Common = /** @class */ (function () {
    function Common() {
    }
    return Common;
}());

//author:kakake
var tsAdminController = /** @class */ (function () {
    function tsAdminController() {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn()
        };
        this.DeptModel = {
            model: {
                DeptId: 0,
                Name: "",
                Pym: "",
                Code: "",
                DelFlag: 0,
                SortOrder: 0
            },
            tablename: "BaseDept",
            key: "DeptId",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {}
        };
        this.PositionModel = {
            model: {
                ID: 0,
                PositionCode: "",
                PositionName: "",
                DelFlag: 0,
                ParentId: 0
            },
            tablename: "BasePosition",
            key: "ID",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {}
        };
        this.SymptomModel = {
            model: {
                SymId: 0,
                Symptom: "",
                ClassId: 0,
                ClassType: 0,
                DelFlag: 0,
                SortOrder: 0,
                DeptCode: ""
            },
            tablename: "BaseSymptom",
            key: "SymId",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {}
        };
        this.SymptomClassModel = {
            model: {
                ClassId: 0,
                ClassCode: "",
                ClassName: "",
                ParentId: 0,
                PositionCode: "",
                ClassType: 0,
                DelFlag: 0,
                SortOrder: 0
            },
            tablename: "BaseSymptomClass",
            key: "ClassId",
            val: "0",
            objval: {},
            where: "",
            pageinfo: {}
        };
    }
    tsAdminController.prototype.getDeptList = function () {
        var deptName = TSLobsterAPI.Program.RequestQuery("deptName", "");
        var delFlag = TSLobsterAPI.Program.RequestQuery("delFlag", -1);
        var pageInfo = {
            key: "DeptId",
            page: TSLobsterAPI.Program.RequestQuery('page', 0),
            perPage: TSLobsterAPI.Program.RequestQuery('limit', 10),
            totalRecord: 0,
            totalPage: 0
        };
        var dbparams = {
            workid: TSLobsterAPI.Program.GetWorkId(),
            deptName: deptName,
            delFlag: delFlag
        };
        var strsql = "select a.*, \
        isnull((select WorkDeptId from  HG_DeptToWork where DeptCode=a.Code and WorkId=@workid),'') as WorkDeptId\
        ,isnull((select WorkDeptName from  HG_DeptToWork where DeptCode=a.Code and WorkId=@workid),'') as WorkDeptName\
         from basedept a \
        where 1=1";
        if (deptName != "") {
            strsql += " and a.Name like @deptName ";
        }
        if (parseInt(delFlag) > -1) {
            strsql += "  and a.DelFlag=@delFlag ";
        }
        return { list: TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparams, pageInfo), count: pageInfo.totalRecord };
    };
    tsAdminController.prototype.updateDeptState = function () {
        var deptId = TSLobsterAPI.Program.RequestQuery("deptId", 0);
        var status = TSLobsterAPI.Program.RequestQuery("status", 0);
        var strsql = "update BaseDept set DelFlag=@status where deptId=@deptId";
        var dbparams = {
            deptId: deptId,
            status: status
        };
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, dbparams);
        return { result: true };
    };
    tsAdminController.prototype.saveDept = function () {
        var dept = JSON.parse(TSLobsterAPI.Program.RequestBody());
        var strsql = "select count(1) val from BaseDept where Name=@Name and DeptId<>@DeptId";
        var dbparams = {
            Name: dept.Name,
            DeptId: dept.DeptId
        };
        var res = TSLobsterAPI.DbHelper.DbGetJsonObject(this.data.dbConn, strsql, dbparams);
        if (parseInt(res.val) > 0) {
            throw "已经存在" + dept.Name + "科室";
        }
        this.DeptModel.objval = dept;
        TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.DeptModel);
        return { result: true };
    };
    tsAdminController.prototype.getPositionList = function () {
        var strsql = "select * from BasePosition ";
        var data = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql);
        return { positionList: data };
    };
    tsAdminController.prototype.savePostion = function () {
        var position = JSON.parse(TSLobsterAPI.Program.RequestBody());
        var strsql = "select count(1) val from BasePosition where (PositionCode=@PositionCode or PositionName=@PositionName) and ID<>@ID";
        var dbparams = {
            PositionCode: position.PositionCode,
            PositionName: position.PositionName,
            ID: position.ID
        };
        var ret = TSLobsterAPI.DbHelper.DbGetJsonObject(this.data.dbConn, strsql, dbparams);
        if (ret.val > 0) {
            throw "已经存在该【" + position.PositionCode + ":" + position.PositionName + "】部位";
        }
        this.PositionModel.objval = position;
        TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.PositionModel);
    };
    tsAdminController.prototype.getSymptomList = function () {
        var classId = TSLobsterAPI.Program.RequestQuery("classId", "");
        var pid = TSLobsterAPI.Program.RequestQuery("pid", "");
        var pageInfo = {
            key: "SymId",
            page: TSLobsterAPI.Program.RequestQuery('page', 0),
            perPage: TSLobsterAPI.Program.RequestQuery('limit', 10),
            totalRecord: 0,
            totalPage: 0
        };
        var dbparams = {
            pid: pid,
            classId: classId
        };
        var strsql = "select a.*, b.ClassName,c.PositionName,c.ID as PosID,c.PositionCode,d.Name as DeptName from [BaseSymptom] a left join [BaseSymptomClass] b on a.ClassId=b.ClassId\
        left join [BasePosition] c on b.PositionCode=c.PositionCode\
        left join BaseDept d on a.DeptCode=d.Code where 1=1";
        if (parseInt(pid) > 0) {
            strsql += " and (c.ID=@pid or c.ParentId=@pid) ";
        }
        if (parseInt(classId) > 0) {
            strsql += "  and a.ClassId=@classId ";
        }
        return { list: TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql, dbparams, pageInfo), count: pageInfo.totalRecord };
    };
    tsAdminController.prototype.getSymptomClassList = function () {
        var strsql = "select * from BaseSymptomClass where 1=1";
        var strsql2 = "select * from BaseDept where 1=1";
        var symptomClassList = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql);
        var deptList = TSLobsterAPI.DbHelper.DbGetJsonData(this.data.dbConn, strsql2);
        return { symptomClassList: symptomClassList, deptList: deptList };
    };
    tsAdminController.prototype.saveSymptom = function () {
        var symptom = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.SymptomModel.objval = symptom;
        TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.SymptomModel);
    };
    tsAdminController.prototype.updateSymptomState = function () {
        var id = TSLobsterAPI.Program.RequestQuery("id", 0);
        var status = TSLobsterAPI.Program.RequestQuery("status", 0);
        var strsql = "update BaseSymptom set DelFlag=@status where SymId=@id";
        var dbparams = {
            id: id,
            status: status
        };
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, dbparams);
    };
    tsAdminController.prototype.saveSymptomClass = function () {
        var symptomClass = JSON.parse(TSLobsterAPI.Program.RequestBody());
        this.SymptomClassModel.objval = symptomClass;
        TSLobsterAPI.DbHelper.SaveModel(this.data.dbConn, this.SymptomClassModel);
    };
    tsAdminController.prototype.updateSymptomClassState = function () {
        var ClassId = TSLobsterAPI.Program.RequestQuery("ClassId", 0);
        var status = TSLobsterAPI.Program.RequestQuery("status", 0);
        var strsql = "update BaseSymptomClass set DelFlag=@status where ClassId=@ClassId";
        var dbparams = {
            ClassId: ClassId,
            status: status
        };
        TSLobsterAPI.DbHelper.DbExecuteUpdate(this.data.dbConn, strsql, dbparams);
        return { result: true };
    };
    return tsAdminController;
}());

//author:kakake
var tsAdminDao = /** @class */ (function () {
    function tsAdminDao() {
        this.dbConn = TSLobsterAPI.Program.GetDbConn();
    }
    return tsAdminDao;
}());

//author:kakake
var tsAdminService = /** @class */ (function () {
    function tsAdminService() {
    }
    return tsAdminService;
}());

